package com.qfedu.mavenk.demo9;

import com.qfedu.mavenk.demo7.Users;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Component;

/**
 * @author:huayuzhuo
 * @email:2798866329@qq.com
 * @desc:
 * @datatime: 2022/10/24 16:44
 */
@Component
public class CustomEventPublisher implements ApplicationEventPublisherAware {
    //发送类
    ApplicationEventPublisher publisher;
    //面实例化，tonggset方法注入该对象
    @Override
    public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
        this.publisher = applicationEventPublisher;
    }

    public void publish(){
        //把事件注册到发送
        publisher.publishEvent(new CustomEvent(this,null));
    }

    public static void main(String[] args) {
        ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
        CustomEventPublisher custom = (CustomEventPublisher) context.getBean("customEventPublisher");
        custom.publish();
    }
}
